<?php

/*
  PHP version 5
  Copyright (c) 2002-2010 ECISP.CN
  声明：这不是一个免费的软件，请在许可范围内使用

  作者：Bili E-mail:huangqyun@163.com  QQ:6326420
  http://www.ecisp.cn	http://www.easysitepm.com
 */
class mainpage extends connector {

	function mainpage() {
		$this->softbase(false);
	}

	function in_list() {
		parent::start_pagetemplate();
		$lng = (admin_LNG == 'big5') ? $this->CON['is_lancode'] : admin_LNG;
		$fgid = intval($this->fun->accept('fgid', 'G'));
		if (empty($fgid)) {
			$this->callmessage($this->lng['db_err'], $_SERVER['HTTP_REFERER'], $this->lng['gobackurlbotton']);
		}
		$form = $this->get_form_purview($fgid);
		$form['action'] = $this->get_link('acform', $form, admin_LNG);
		$attrread = $this->get_formatt($fgid);
		$template = $form['template'];

		$this->pagetemplate->assign('path', 'form');
		$this->pagetemplate->assign('current', $fgid);
		$this->pagetemplate->assign('form', $form);
		$this->pagetemplate->assign('attr', $attrread);

		$this->pagetemplate->assign('seccodelink', $this->get_link('seccode'));

		$templatesDIR = $this->get_templatesdir('form');

		$templatefilename = $lng . '/' . $templatesDIR . '/' . $template;
		$this->pagetemplate->display($templatefilename, $form['formcode'] . '_list', false, $filename, admin_LNG);
	}

	function in_save() {
		$fgid = intval($this->fun->accept('fgid', 'P'));
		if (empty($fgid)) {
			$this->callmessage($this->lng['db_err'], $_SERVER['HTTP_REFERER'], $this->lng['gobackurlbotton']);
		}
		$formcode = $this->fun->accept('formcode', 'P');
		$countattrs = $this->fun->accept('countattrs', 'P');
		$emailatt = rtrim($this->fun->accept('emailatt', 'P'));
		$formatt = $this->fun->accept('formatt', 'P', true, true);
		$form = $this->get_form_purview($fgid);
		$ipadd = $this->fun->ip($_SERVER['REMOTE_ADDR']);
		$usersessionid = md5($ipadd + $formcode . 'input');
		$inputseesion = $this->fun->accept($usersessionid, 'C');

		$did = intval($this->fun->accept('did', 'P'));
		$did = empty($did) ? 0 : $did;

		$userid = intval($this->member_cookieview('userid'));
		$userid = empty($userid) ? 0 : $userid;
		$addtime = time();
		$linkURL = $_SERVER['HTTP_REFERER'];

		if ($form['isseccode']) {
			$seccode = $this->fun->accept('seccode', 'P');
			include_once admin_ROOT . '/public/class_seccode.php';
			list($new_seccode, $expiration) = explode("\t", $this->fun->eccode($_COOKIE['ecisp_home_seccode'], 'DECODE'));
			$code = new seccode();
			$code->seccodeconvert($new_seccode);
			if ($new_seccode != strtoupper($seccode)) {
				$this->callmessage($this->lng['seescodeerr'], $linkURL, $this->lng['gobackbotton']);
			}
		}

		if (empty($inputseesion) && $form['isinputtime']) {
			$this->fun->setcookie($usersessionid, $addtime, $form['inputtime']);
		} elseif ($form['isinputtime']) {

			$this->callmessage($this->lng['repeatinput'], $linkURL, $this->lng['gobackurlbotton']);
		}
		if ($form['purview'] > 0) $this->member_purview($form['purview']);
		$email = $formatt[$form['emailatt']];

		$db_table = db_prefix . 'form_time';
		$db_table2 = db_prefix . 'form_value';
		$db_field = 'fgid,addtime,email,isclass,isreply,iplong';
		$db_values = "$fgid,$addtime,'$email',0,0,$ipadd";
		$this->db->query('INSERT INTO ' . $db_table . ' (' . $db_field . ') VALUES (' . $db_values . ')');
		$insert_id = $this->db->insert_id();
		if (!empty($formatt) && is_array($formatt)) {

			$db_field = 'fgid,ftid,did,userid,attrvalue,iscount';
			$attrvalue = addslashes(serialize($formatt));
			$db_values = "$fgid,$insert_id,$did,$userid,'$attrvalue',$form[iscount]";
			$this->db->query('INSERT INTO ' . $db_table2 . ' (' . $db_field . ') VALUES (' . $db_values . ')');
		}

		if ($form['ismail'] && $form['tmid']) {
			$this->formmailsend($form['tmid'], $insert_id);
		}
		if ($this->CON['is_email'] == 1) {
			$this->formmailsend(0, $insert_id, 'feedbackwarn');
		}
		$this->callmessage($form['successtext'], $linkURL, $this->lng['gobackurlbotton']);
	}

}
?>